﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.InteropServices.Automation;

namespace SuperLauncher
{
    public partial class InstallNESLPage : UserControl
    {
        public InstallNESLPage()
        {
            InitializeComponent();
        }

        public bool NESLInstallAtstartup()
        {
            try
            {
                if (!Application.Current.HasElevatedPermissions || !AutomationFactory.IsAvailable)
                {
                    return false;
                }

                if (Microsoft.Silverlight.Windows.Installer.CheckNESLInstalled(2, 1) == false)
                {
                    Microsoft.Silverlight.Windows.Installer.InstallNESL(new Uri("NESLSetup/NESLSetup.msi", UriKind.Relative), false, true);

                    if (Microsoft.Silverlight.Windows.Installer.CheckNESLInstalled(2, 1) == false)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                else
                {
                    //NESL already installed 
                    return true;
                }
            }
            catch (Exception Ex)
            {
                return false;
            }
        }
    }
}
